<?php session_start();?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>主页</title>
<link href="../css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript">
function validate_form(thisform)
{
with (thisform)
  {
  if(content.value == ''){
	  alert("留言不能为空");
	  content.focus();
	  return false;
  }else{
	 
  }
  }
}
function response(agree,requester,receiver){
	var xmlhttp;
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
 	}else{// code for IE6, IE5
 		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
		xmlhttp.open("GET","../handle/response_add_friends.php?agree="+agree+"&requester="+requester+"&receiver="+receiver);
		xmlhttp.send();
	if(agree == 1){
		alert("添加好友成功!!");
	}else if(agree == 0){
		alert("你已拒绝该请求!");
	}else{}
	location.reload();
}
</script>
</head>
<body>
<?php require '../public/header.php' ?> 
<!-- 导航栏 -->
<ul class="nav nav-pills">
   <li><a href="home.php">主页</a></li>
   <li><a href="message_record.php">留言记录</a></li>
   <li><a href="friends.php">我的好友</a></li>
   <li><a href="add_friends.php">添加好友</a></li>
   <li class="active"><a href="#">我的消息</a></li>
</ul><hr/>
<!-- 留言记录 -->
<div class="panel panel-info"> 	
	<div class="panel-heading" id="message_record">
      <h3 class="panel-title">好友申请消息</h3>
   </div>
   <div class="panel-body">
		<?php
		if(isset($_SESSION['username'])){
			require('../public/conn.php');
			$username = $_SESSION['username'];
			$query = "SELECT * FROM add_friends_applys WHERE apply_receiver='$username'";//找接受者是本人的记录
			$result=mysql_query($query);
			$hasNotice = false;
			if($result){
				$receiver = $username;
			while($row = mysql_fetch_array($result)){
				$requester = $row['apply_requester'];
				echo "<div>";
				echo "<div style='width:40%;float:left;'>
						用户&nbsp;
						<a href='#'>".$requester."</a>
						&nbsp;申请加你为好友
					  </div>";
				echo '<div style="width:40%;float:left;">
						<button type="button" class="btn btn-primary" 
								onClick="response('."1,'"                                  .$requester."','".$receiver."'".')">
				        		同意												                        </button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<button type="button" class="btn btn-primary" 
								onClick="response('."1,'"                                  .$requester."','".$receiver."'".')">
				        		拒绝													                        </button>
					  </div>';
				echo '</div><br/><br/>';
				$hasNotice = true;
			}}
			if(!$hasNotice){
				echo "暂无好友申请消息";
			}		
		}else{
			echo "亲,先去<a href='../face/login-face.php'><span>登陆</span>                </a>吧！";	
		}
		?>
    </div>
</div>
</div>
<?php require('../public/footer.php');?>
</body>
</html>
